package model.components.nodes.factory;

import model.components.nodes.node.VirtualNode;
import model.components.nodes.node.VirtualRouter;
import model.components.nodes.node.VirtualServer;
import model.components.nodes.node.VirtualSwitch;

public class VirtualNodesFactory extends NodesFactory
{	
	public static final int ROUTERS_PERCENTAGE = 0;
	public static final int SWITCHES_PERCENTAGE = 0;
	public static final int SERVERS_PERCENTAGE = 100;
	
	public static final int LINUX_PERCENTAGE = 100;
	public static final int WINDOWS_PERCENTAGE = 0;
	public static final int SOLARIS_PERCENTAGE = 0;
	public static final int ANDROID_PERCENTAGE = 0;
	
	public static final int VMWARE_PERCENTAGE = 100;
	public static final int XEN_PERCENTAGE = 0;
	public static final int KVM_PERCENTAGE = 0;
	public static final int UML_PERCENTAGE = 0;
	
	public static final int MIN_CPU = 1;
	public static final int MAX_CPU = 20;
	
	public static final int MIN_MEMORY = 1;
	public static final int MAX_MEMORY = 20;
	
	public static final int MIN_DISK_SPACE = 1;
	public static final int MAX_DISK_SPACE = 20;
	
	private int startingDate;
	public int getStartingDate(){ return startingDate; }
	public void setStartingDate( int startingDate ){ this.startingDate = startingDate; }
	
	private int endingDate;
	public int getEndingDate(){ return endingDate; }
	public void setEndingDate( int endingDate ){ this.endingDate = endingDate; }
	
	public VirtualNodesFactory( String networkName, int startingDate, int endingDate )
	{
		super( networkName, ROUTERS_PERCENTAGE, SWITCHES_PERCENTAGE, SERVERS_PERCENTAGE, LINUX_PERCENTAGE, WINDOWS_PERCENTAGE, SOLARIS_PERCENTAGE, ANDROID_PERCENTAGE, VMWARE_PERCENTAGE, XEN_PERCENTAGE, KVM_PERCENTAGE, UML_PERCENTAGE, MIN_CPU, MAX_CPU, MIN_MEMORY, MAX_MEMORY, MIN_DISK_SPACE, MAX_DISK_SPACE );
		
		this.setStartingDate( startingDate );
		this.setEndingDate( endingDate );
	}

	public VirtualNodesFactory( String networkName, int startingDate, int endingDate, int routersPercentage, int switchesPercentage, int serversPercentage, int linuxPercentage, int windowsPercentage, int solarisPercentage, int androidPercentage, int vmWarePercentage, int xenPercentage, int kvmPercentage, int umlPercentage, int minCpu, int maxCpu, int minMemory, int maxMemory, int minDiskSpace, int maxDiskSpace )
	{
		super( networkName, routersPercentage, switchesPercentage, serversPercentage, linuxPercentage, windowsPercentage, solarisPercentage, androidPercentage, vmWarePercentage, xenPercentage, kvmPercentage, umlPercentage, minCpu, maxCpu, minMemory, maxMemory, minDiskSpace, maxDiskSpace );
		
		this.setStartingDate( startingDate );
		this.setEndingDate( endingDate );
	}
	
	@Override
	public VirtualNode create()
	{
		VirtualNode virtualNode = null;
		int randomNodeTypePercentage = (int) (100 * Math.random());
		
		if( 0 <= randomNodeTypePercentage && randomNodeTypePercentage < this.getRoutersPercentage() )
			virtualNode = new VirtualRouter( this.getNetworkName(), this.getStartingDate(), this.getEndingDate(), this.getNodeCount(), this.randomOperatingSystem(), this.randomVirtualEnvironment(), this.randomCpu(), this.randomMemory() );
		
		else if( this.getRoutersPercentage() <= randomNodeTypePercentage && randomNodeTypePercentage < this.getRoutersPercentage() + this.getSwitchesPercentage() )
			virtualNode = new VirtualSwitch( this.getNetworkName(), this.getStartingDate(), this.getEndingDate(), this.getNodeCount(), this.randomOperatingSystem(), this.randomVirtualEnvironment(), this.randomCpu(), this.randomMemory() );
		
		else if( this.getRoutersPercentage() + this.getSwitchesPercentage() <= randomNodeTypePercentage && randomNodeTypePercentage < 100 )
			virtualNode = new VirtualServer( this.getNetworkName(), this.getStartingDate(), this.getEndingDate(), this.getNodeCount(), this.randomOperatingSystem(), this.randomVirtualEnvironment(), this.randomCpu(), this.randomMemory(), this.randomDiskSpace() );
		
		if( virtualNode != null )
			this.setNodeCount( this.getNodeCount() + 1 );
		
		return virtualNode;
	}
	
}
